/**
 * 
 */
package com.huawei.esdk.uc.sametime.services;

import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;

import com.huawei.esdk.uc.jna.UCService;
import com.huawei.esdk.uc.jna.Constants.AccountType;
import com.huawei.esdk.uc.jna.Constants.ContactAvailability;
import com.huawei.esdk.uc.sametime.util.ImageFactory;

/**
 * @author y00175154
 * 
 */
public class UCPresenceService
{

    /**
     * 根据用户ID，调用UC SDK的状态获取接口，从而得到该用户的当前的状态值
     * @param ucAccount
     * @return
     */
    public static int getCurrentPresence(String ucAccount)
    {
        return UCService.getInstance().UC_SDK_GetContactStatus(
                AccountType.UC_ACCOUNT, ucAccount);
    }

    public static Image getUCStatusImage(int status)
    {
        Image statusImage;
        if (ContactAvailability.Online == status)
        {
            statusImage = getImage(ImageFactory.ICON_UCSTATUS_AVAILABLE);
        }
        else if (ContactAvailability.Busy == status)
        {
            statusImage = getImage(ImageFactory.ICON_UCSTATUS_BUSY);
        }
        else if (ContactAvailability.Leave == status
                || ContactAvailability.NoDisturb == status)
        {
            statusImage = getImage(ImageFactory.ICON_UCSTATUS_DND);
        }
        else
        {
//            statusImage = getImage(ImageFactory.ICON_UCSTATUS_UNKNOWN);
            statusImage = null;
        }

        return statusImage;
    }

    private static Image getImage(String imgPath)
    {
        return ImageFactory.loadImage(Display.getCurrent(), imgPath);
    }
}
